﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;

namespace NuaTarDoneng
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            pageset.setMeta("NuaTar小站", "时事评论、编程的心得、软件使用心得、LinkUp开源项目", this);
            if (null != this.Request.QueryString["id"])
            {   
                string id=this.Request.QueryString["id"];
                if ( id== "all")
                {
                    SqlDataSource1.SelectCommand = "select * from blogs";
                }
                else
                {
                    SqlDataSource1.SelectCommand = "select * from blogs where SortID='" + id + "'";
                }
            }
        }
        

        protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        protected string getSortNameById(string id)
        {
            SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["constr"]);
            SqlCommand cmd = cnn.CreateCommand();
            cmd.CommandText = "select blogSort from [blogSort] where blogSortID='" + id + "'";
            cnn.Open();
            string i = Convert.ToString(cmd.ExecuteScalar());
            cnn.Close();
            return i;
        }
        protected string getRealContentShort(string content)
        {
            string trueStr = System.Text.Encoding.Default.GetString(Convert.FromBase64String(content));
            string a = checkStr(trueStr);
            return (trueStr.Length > 300) ? trueStr.Substring(0, 300) + "........" : trueStr;
        
        }
        protected string getShortTime(string times)
        {
            DateTime dts = DateTime.Parse(times);
            string day = dts.Day.ToString();
            string month = dts.Month.ToString();
            string year = dts.Year.ToString();
            return "<h1 style=\"padding:0px;margin:0px\">"+day+"</h1>" + year + "-" + month;
        
        }
        private string checkStr(string html)
        {
            string source = html;
            string reg = @"[<].*?[>]";
            source = System.Text.RegularExpressions.Regex.Replace(source, reg, "");
            source = source.Replace("\r\n", "").Replace(" ", "").Replace("\t", "");
            return source;
        }
    }
    
}
